/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package WebServices;

import SessionBeans.AutoServicioFacade;
import SessionBeans.FacturaFacade;
import SessionBeans.HotelServicioFacade;
import SessionBeans.ModeloHabitacionFacade;
import SessionBeans.PersonaPublicaFacade;
import SessionBeans.ProveedorFacade;
import SessionBeans.TourServicioFacade;
import SessionBeans.TransporteServicioFacade;
import entity.AutoServicio;
import entity.Factura;
import entity.Habitacion;
import entity.HotelServicio;
import entity.ModeloHabitacion;
import entity.PersonaPublica;
import entity.Proveedor;
import entity.Servicio;
import entity.TourServicio;
import entity.TransporteServicio;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
import javax.jws.Oneway;

/**
 *
 * @author javier
 */
@WebService(serviceName = "ClientePesadoWS",wsdlLocation="META-INF/wsdl/ClientePesadoWS.wsdl")
@Stateless()
public class ClientePesadoWS {
    
    @EJB
    private ProveedorFacade ejbRefPro;// Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Web Service Operation")
    
    @EJB
    private FacturaFacade ejbRefFactura;// Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Web Service Operation")
    
    @EJB
    private HotelServicioFacade ejbRefHotelServicio;// Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Web Service Operation")
        
    @EJB
    private TourServicioFacade ejbRefTourServicio;// Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Web Service Operation")
    
    @EJB
    private AutoServicioFacade ejbRefAutoServicio;// Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Web Service Operation")

    @EJB
    private TransporteServicioFacade ejbRefTransporteServicio;// Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Web Service Operation")
     
    @EJB
    private ModeloHabitacionFacade ejbRefModeloHabitacionFacade;
    
    @EJB
    private PersonaPublicaFacade ejbRefPersonaPublica;// Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Web Service Operation")    

    @WebMethod(operationName = "obtenerPersonasXServicio")
    public List<PersonaPublica> obtenerPersonasXServicio(@WebParam(name = "servicio")
    Servicio servicio) {
        return ejbRefPersonaPublica.obtenerPersonasXServicio(servicio);
    }
     
    @WebMethod(operationName = "createProveedor")
    @Oneway
    public void createProveedor(@WebParam(name = "entity")
    Proveedor entity) {
        ejbRefPro.create(entity);
    }
    
    @WebMethod(operationName = "findHotelServicio")
    public HotelServicio findHotelServicio(@WebParam(name = "id")
    Object id) {
        return ejbRefHotelServicio.find(id);
    }   

    @WebMethod(operationName = "findTourServicio")
    public TourServicio findTourServicio(@WebParam(name = "id")
    Object id) {
        return ejbRefTourServicio.find(id);
    }
    
    @WebMethod(operationName = "findAutoServicio")
    public AutoServicio findAutoServicio(@WebParam(name = "id")
    Object id) {
        return ejbRefAutoServicio.find(id);
    }   
    
    @WebMethod(operationName = "findTransporteServicio")
    public TransporteServicio findTransporteServicio(@WebParam(name = "id")
    Object id) {
        return ejbRefTransporteServicio.find(id);
    }
    
    @WebMethod(operationName = "obtenerFacturasXServicio")
    public List<Factura> obtenerFacturasXServicio(@WebParam(name = "servicio")
    Servicio servicio, @WebParam(name = "fechaInicio")
    Date fechaInicio, @WebParam(name = "fechaFin")
    Date fechaFin) {
        return ejbRefFactura.obtenerFacturasXServicio(servicio, fechaInicio, fechaFin);
    }
    
    @WebMethod(operationName = "editProveedor")
    @Oneway
    public void editProveedor(@WebParam(name = "entity")
    Proveedor entity) {
        ejbRefPro.edit(entity);
    }

    @WebMethod(operationName = "removeProveedor")
    @Oneway
    public void removeProveedor(@WebParam(name = "entity")
    Proveedor entity) {
        ejbRefPro.remove(entity);
    }

    @WebMethod(operationName = "logInProveedor")
    public Proveedor logInProveedor(@WebParam(name = "usuario")
    String usuario, @WebParam(name = "pass")
    String pass) {
        return ejbRefPro.logIn(usuario, pass);
    }
     @WebMethod(operationName = "crearProveedor")
    @Oneway
    public void crearProveedor(@WebParam(name = "usuario")
    String usuario, @WebParam(name = "pass")
    String pass,@WebParam(name="email")String email, @WebParam(name = "razonSocial")
    String razonSocial, @WebParam(name = "pais")
    String pais, @WebParam(name = "direccion")String direccion ) {
        Proveedor pro = new Proveedor();
        pro.setUsuario(usuario);
        pro.setPass(pass);
        pro.setEmail(email);
        pro.setRazonSocial(razonSocial);
        pro.setPais(pais);
        pro.setDireccion(direccion);
        ejbRefPro.create(pro);
    }
     
     @WebMethod(operationName = "find")
    public Proveedor find(@WebParam(name = "id")
    Object id) {
        return ejbRefPro.find(id);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "modificarModeloHabitacion")
    @Oneway
    public void modificarModeloHabitacion(@WebParam(name = "idModeloHabitacion")
    String idModeloHabitacion, @WebParam(name = "cantidadCamas")
    String cantidadCamas, @WebParam(name = "precio")
    String precio) {
        ModeloHabitacion modeloHabitacion = ejbRefModeloHabitacionFacade.find(Integer.parseInt(idModeloHabitacion));
        modeloHabitacion.setNumeroCamas(Integer.parseInt(cantidadCamas));
        modeloHabitacion.setPrecio(Float.parseFloat(precio));
        ejbRefModeloHabitacionFacade.edit(modeloHabitacion);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "crearHabitacion")
    @Oneway
    public void crearHabitacion(@WebParam(name="idServicio")int idServicio, @WebParam(name = "numero")
    int numero, @WebParam(name = "idModeloHabitacion")
    int idModeloHabitacion) {
        HotelServicio hotelServicio = ejbRefHotelServicio.find(idServicio);
        Habitacion habitacion = new Habitacion();
        for(Iterator<ModeloHabitacion> it = hotelServicio.getModelosHabitaciones().iterator();it.hasNext();){
            ModeloHabitacion modeloHabitacion = it.next();
            if(modeloHabitacion.getId()==idModeloHabitacion){
                habitacion.setTipo(modeloHabitacion);                
            }            
        }
        habitacion.setNumero(numero);
        hotelServicio.getHabitaciones().add(habitacion);
        ejbRefHotelServicio.edit(hotelServicio);        
    }
    
       
        
}
